﻿using AutoMapper;
using Ideaa.Data.Models;
using Ideaa.Data.Models.Base;
using Ideaa.Data.Models;
using Ideaa.Web.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ideaa.Web.Mappings
{
    public class DomainToViewModelMappingProfile : Profile
    {
        public override string ProfileName
        {
            get { return "DomainToViewModelMappings"; }
        }

        protected override void Configure()
        {
            Mapper.CreateMap<BaseEntity, BaseEntityModel>()
                .Include<Idea, IdeaModel>()
                .Include<Suggestion, SuggestionModel>()
                .Include<Vote, VoteModel>()
                .ForMember(dest => dest.Username,
                    opt => opt.MapFrom(src => src.User != null ? src.User.UserName : "<anonymous>"));

            Mapper.CreateMap<Idea, IdeaModel>()
                .ForMember(
                    x => x.Suggestions,
                    options => options.MapFrom(
                        src => 
                            Mapper.Map<IEnumerable<Suggestion>, IEnumerable<SuggestionModel>>(src.Suggestions)));
                
            
            Mapper.CreateMap<Suggestion, SuggestionModel>()
                .ForMember(dest => dest.VoteModels, opt => opt.Ignore());
        }
    }
}
